package projectServlet;

import java.io.IOException;
import java.util.ArrayList;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import dao.DAOException;
import dao.EmployeeDAOFactory;
import dao.mysql.EmployeeDAOFactoryImpl;
import dto.UserDTO;

/**
 * Servlet implementation class AdminListPreset
 */
@WebServlet("/AdminListPreset")
public class AdminListPreset extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public AdminListPreset() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		EmployeeDAOFactory eFactory = new EmployeeDAOFactoryImpl();
		ArrayList<UserDTO>			   user     = new ArrayList<UserDTO>();
		try {
			user = eFactory.getEmployeeDAO().findAllUser();
		} catch (DAOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		request.getSession().setAttribute("AfterSearch", false);	
		
		request.setAttribute("alluser", user);
		RequestDispatcher rd = request.getRequestDispatcher("/adminlist.jsp");
		rd.forward(request, response);	
		
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request,response);
	}

}
